﻿using PLCSharp.Views.Authority;
using Prism.Commands;
using Prism.Dialogs;
using Prism.Mvvm;

namespace PLCSharp.CoreModel.Prism
{
    public class NavigateItem : BindableBase, IComparable<NavigateItem>
    {
        public NavigateItem(IDialogService dialogService)
        {
            _dialogService = dialogService;

        }
        private string _ViewName;

        public string ViewName
        {
            get { return _ViewName; }
            set { SetProperty(ref _ViewName, value); }
        }

        private string _IconKind;

        public string IconKind
        {
            get { return _IconKind; }
            set { SetProperty(ref _IconKind, value); }
        }

        private string _DisplayName;

        public string DisplayName
        {
            get { return _DisplayName; }
            set { SetProperty(ref _DisplayName, value); }
        }

        private Authority _UserLevel;

        public Authority UserLevel
        {
            get { return _UserLevel; }
            set { SetProperty(ref _UserLevel, value); }
        }

        private bool _Display;

        public bool Display
        {
            get { return _Display; }
            set { SetProperty(ref _Display, value); }
        }

        public int Index { get; set; }

        public int CompareTo(NavigateItem other)
        {
            if (other == null) return 1;
            if (Index > other.Index) return -1;
            else return 1;
        }


        private DelegateCommand _Open;
        public DelegateCommand Open =>
            _Open ??= new DelegateCommand(ExecuteOpen);

        void ExecuteOpen()
        {
            if (ShowList.Contains(ViewName) == false)
            {
                ShowList.Add(ViewName);
                try
                {

        
                _dialogService.Show(ViewName, r =>
                {
                    if (ShowList.Contains(ViewName)) {

                        ShowList.Remove(ViewName);
                    }

                });
                }
                catch (Exception)
                {

                    ShowList.Remove(ViewName);
                }
            }
        }

        private List<string> ShowList = [];
        IDialogService _dialogService { get; set; }
    }
}